package com.alibaba.csp.sentinel.dashboard.rule.utils;

import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.authority.InnerAuthority;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.flow.InnerFlow;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.param.InnerParam;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class MyConverter {
    public static String convertFlow(List<FlowRuleEntity> rules) {
        List<InnerFlow> innerFlows = new ArrayList<>();
        rules.forEach(e -> {
            InnerFlow innerFlow = new InnerFlow();
            BeanUtils.copyProperties(e, innerFlow);
            innerFlows.add(innerFlow);
        });
        return JSON.toJSONString(innerFlows);
    }
    public static String convertDegrade(List<DegradeRuleEntity> rules) {
        return JSON.toJSONString(rules);
    }
    public static String convertSystem(List<SystemRuleEntity> rules) {
        return JSON.toJSONString(rules);
    }
    public static String convertParamFlow(List<ParamFlowRuleEntity> rules) {
        List<InnerParam> innerParams =new ArrayList<>();
        rules.forEach(e->{
            InnerParam innerParam = new InnerParam();
            BeanUtils.copyProperties(e,innerParam);
            innerParams.add(innerParam);
        });
        return JSON.toJSONString(innerParams);
    }
    public static String convertAuthority(List<AuthorityRuleEntity> rules) {
        List<InnerAuthority> innerAuthorities =new ArrayList<>();
        rules.forEach(e->{
            InnerAuthority innerAuthority = new InnerAuthority();
            BeanUtils.copyProperties(e,innerAuthority);
            innerAuthorities.add(innerAuthority);
        });
        return JSON.toJSONString(innerAuthorities);
    }
    private MyConverter(){}
}

